package fr.inserm.u915.organifooyi.web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

public class RequestHandler
	{
	private HttpServletRequestWrapper request;
	private HttpServletResponseWrapper response;
	public RequestHandler()
		{
		}
	
	public HttpServletRequestWrapper getRequest() {
		return request;
		}
	public void setRequest(HttpServletRequestWrapper request) {
		this.request = request;
		}
	public HttpServletResponseWrapper getResponse() {
		return response;
		}
	public void setResponse(HttpServletResponseWrapper response) {
		this.response = response;
		}
	
	public int forwardTo(String path) throws IOException,ServletException
		{
		RequestDispatcher dispatcher=getRequest().getRequestDispatcher(path);
		if(dispatcher==null) throw new NullPointerException("? path="+path);
		dispatcher.forward(getRequest(), getResponse());
		return 0;
		}
	

	
	public Path getPath()
		{
		return new Path(getRequest().getPathInfo());
		}
	public ServletContext getServletContext()
		{
		return getRequest().getServletContext();
		}
	
	public void log(Object o)
		{
		getServletContext().log(String.valueOf(o));
		}
	
	public void close()
		{
		
		}
	protected boolean isEmpty(String s)
		{
		return s==null || s.trim().isEmpty();
		}
	
	public int service() throws IOException,ServletException
		{
		return -1;
		}
	}
